/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1629206489712_6257';

  // add your middleware config here 增加配置中间件
  config.middleware = ['printdate', 'forbidip'];
  config.forbidip = {
    forbidips: [
      '::1'
    ]
  }

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  // 配置模板引擎
  config.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.tpl': 'nunjucks',
    },
  };
  config.sequelize = {
    dialect: 'mysql', // support: mysql, mariadb, postgres, mssql
    database: 'treehole', //数据库名
    host: '127.0.0.1',
    port: '3306',
    username: 'root', //账号
    password: '123456789', //密码
    timezone: '+08:00', // 保存为本地时区,mysql保存时会自动保存为UTC格式
    dialectOptions: {
      dateStrings: true,
      typeCast(field, next) {
        if (field.type === "DATETIME") {
          return field.string();
        }
        return next();
      }
    }
  };
  config.jwt = {
    secret: "zjp"//自定义 token 的加密条件字符串
  };
  config.cors = {
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
    credentials: true,
    origin: '*',  // 允许的请求来源（* 表示允许所有的IP的请求 ）
  };

  config.security = {
    csrf: {
      enable: false
    }
  };


  return {
    ...config,
    ...userConfig,
  };
};

